#! /bin/sh

# First make the synthetic data for the selecting demo.
echo "Making synthetic data for demo"
######START OF MODEL######
REF1="1.0:-1,0.2;4,0.2"
REF2="1.0:-2,2.0199;3.5495,0"
REF3="1.0:-2,4.3955;3.2384,0"
REF4="1.0:-2,8.8603;3.1155,0"

dvdz=.015  # velocity gradient (dv/dz)
dvdx=-0.2  # velocity gradient (dv/dx)
v00=5.0  # P-wave velocity at surface (S-wave velocity for GAMM>>1) in km/s
nxo=6 fxo=0.04 dxo=0.04  # offset information: number, first, spacing
nxs=12 fxs=1.0 dxs=0.04  # shot information: number, first, spacing

nt=200 dt=0.004 

susynlv v00=$v00 ndpfz=10 dvdz=$dvdz dvdx=$dvdx \
		dt=$dt nt=$nt verbose=0 \
		ref=$REF1 ref=$REF2 ref=$REF3 ref=$REF4 \
		nxo=$nxo fxo=$fxo dxo=$dxo \
		nxs=$nxs fxs=$fxs dxs=$dxs  |
suchw key1=cdp key2=gx key3=sx b=1 c=1 d=2 >modeldata
######END OF MODEL######
echo "Data made, making postscript figures"
# Plot the model
supsimage <modeldata perc=99 title="Shot Gathers"\
	label1="Time (sec)" label2="Shot Gather" f2=1 d2=0.166667 >model.eps
 

######SELECTING EXAMPLES######
# Get a stacking chart
suchart <modeldata |                     
psgraph n=72 title="Stacking Chart" label1="sx" label2="gx" \
 linewidth=0 marksize=2 mark=8 >chart.eps                    

# Select even numbered shot gathers (s=0 is the default in suwind)
# NOTES: The fldr field is usually numbered sequentially as the
#	nominal number of the shot gather.  The sx field usually gives
#	the shot location.  One could select on sx by examining its values
#	with sugethw, e.g.,
#		sugethw <modeldata sx | more
#	to find that the first sx=1000 and that the moveup is 40 between shots.
#	Thus a selecting command equivalent to the
#		suwind <modeldata key=fldr j=2 | ...
#	given below would be
#		suwind <modeldata key=sx s=1040 j=80 | ...
#	But when fldr is set, it is easier to use and we stick to this below.
suwind <modeldata key=fldr j=2 |
#sustack key=fldr | sugethw fldr nhs    # For debugging only
supsimage perc=99 title="Even Shots"\
	label1="Time (sec)" label2="Shot Gather" f2=2 d2=0.33333 >even.eps

# Select odd numbered shot gathers
suwind <modeldata key=fldr j=2 s=1 |
supsimage perc=99 title="Odd Shots"\
	label1="Time (sec)" label2="Shot Gather" f2=1 d2=0.33333 >odd.eps

# Select every other even shot gather between 4th and 8th gather
suwind <modeldata key=fldr j=2 min=4 max=8 |
supsimage perc=99 title="4th-8th Even Shots"\
	label1="Time (sec)" label2="Shot Gather" f2=4 d2=0.33333 >alt.eps

# Windowing Example
# Select middle 36 traces and the middle 100 ms of the time traces
# Remark: suwind NEVER resamples--even if you start between samples.
#         If you want resampling, use suresamp (see next few examples)
# Note that 50 * .004 = 0.2
# Note that tracl is default key for suwind, so not mentioned
suwind <modeldata min=19 count=36 tmin=0.2 nt=100 |
#sugethw tracl ns | sed 18q  # For debugging only
supsimage perc=99 title="Windowed Shots"\
	label1="Time (sec)" label2="Traces" f2=19 d2=1 >middle.eps

# Windowing Example -- same thing, using suresamp
# If you don't need resampling, then suwind is fine.
suwind <modeldata min=19 count=36 |
suresamp tmin=0.2 nt=100 |
#sugethw tracl ns | sed 18q  # For debugging only
supsimage perc=99 title="Windowed Shots (with suresamp)"\
	label1="Time (sec)" label2="Traces" f2=19 d2=1 >resamp.eps

# Subsample to twice .004 = .008 sampling interval, note the
# typical anti-alias filtering before sub-sampling
sufilter <modeldata f=52.5,57.5,62.5 amps=1.0,0.5,0.0 |
suresamp nt=100 dt=.008 |
supsimage perc=99 title="Time Subsampled Shots"\
	label1="Time (sec)" label2="Shot Gather" f2=1 d2=0.166667 >subsamp.eps

# Interpolate time traces to half .004 = .002 sampling interval
suresamp <modeldata nt=400 dt=.002 |
supsimage perc=99 title="Time Interpolated Shots"\
	label1="Time (sec)" label2="Shot Gather" f2=1 d2=0.166667 >interp.eps

# Window to full fold cdp region and sort by cdp
# See the Sort Tutorial for an illustration of using sugethw and susort
# to determine the full fold region.
suwind <modeldata key=cdp min=1100 max=1480 >tmp
susort<tmp cdp offset |
supsimage perc=99 title="Full Fold CDPs"\
	label1="Time (sec)" label2="CDP Gather" f2=1 d2=0.333333 >fullfold.eps
rm tmp


# Get near and far offset sections
# See the Sort Tutorial for determining that the near offsets in the
# full-fold portion of the data vary between 0 and 40 and the fars
# between 160 and 200.
# The count parameter is not important here, but if the data set is
# large (e.g., a tape), then without count set, you search the entire
# tape, so use count when you know how many traces to expect.
suwind <modeldata key=offset min=40 max=80 count=24 |
supswigp perc=99 title="Near Offsets"\
	label1="Time (sec)" label2="CDP Location" f2=1020 d2=20 >near.eps

suwind <modeldata key=offset min=200 max=240 |
supswigp perc=99 title="Far Offsets"\
	label1="Time (sec)" label2="CDP Location" f2=1100 d2=20 >far.eps

# The near and far offsets exhibit two step "jitter", let's use
# every other gather to get true common offset sections.  Again
# use count parameter for illustrative purposes.
suwind <modeldata key=offset min=40 max=40 count=12 |
supswigp perc=99 title="True Common Offset=40"\
	label1="Time (sec)" label2="CDP Location" f2=1020 d2=40 >tco1.eps

suwind <modeldata key=offset min=240 max=240 |
supswigp perc=99 title="True Common Offset=240"\
	label1="Time (sec)" label2="CDP Location" f2=1120 d2=40 >tco2.eps


# Sometimes you know a value is bad and want to reject it.  Let's reject
# the first and last cdp in the last example:
suwind <modeldata key=offset min=240 max=240 |
suwind key=cdp reject=1120,1560 |
supswigp perc=99 title="Reject Offsets 1120,1560"\
	label1="Time (sec)" label2="CDP Location" f2=1160 d2=40 >reject.eps

echo 
echo "Output PostScript files:  model.eps chart.eps even.eps odd.eps alt.eps"
echo "    middle.eps resamp.eps subsamp.eps interp.eps fullfold.eps"
echo "    near.eps far.eps tco1.eps tco2.eps reject.eps"
echo 
echo "You may view these with your PostScript Previewer"

exit
